package com.jiang.jixiang.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.jiang.jixiang.R;
import com.ws.universal.tools.wsui.widget.QMUIRoundButton;


/**
 * @创建者 ws
 * @创建时间 2021/11/2
 * @描述
 */
public class BuyDialog extends Dialog {
    private Context mContext;
    private QMUIRoundButton btnPay;
    private ImageView imgClose;

    private OnDiaogClickListener mListener;

    public BuyDialog(@NonNull Context context) {
        super(context, R.style.dialog_alarm);
        mContext = context.getApplicationContext();
        initUI();
    }


    public void setBtnListener(OnClickListener lListener) {
        btnPay.setTag(lListener);
        btnPay.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                OnClickListener lListener = (OnClickListener) btnPay.getTag();
                lListener.onClick(BuyDialog.this, 0);
            }
        });
    }

    public void setLeftBtnListener(OnClickListener lListener) {
        imgClose.setTag(lListener);
        imgClose.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                OnClickListener lListener = (OnClickListener) imgClose.getTag();
                lListener.onClick(BuyDialog.this, 0);
            }
        });
    }


    private void initUI() {
        View dlgView = LayoutInflater.from(mContext).inflate(R.layout.dialog_buy, null);

        btnPay = dlgView.findViewById(R.id.btnPay);
        imgClose = dlgView.findViewById(R.id.imgClose);
        btnPay.setChangeAlphaWhenPress(true);
        OnClickListener listener = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int arg1) {
                if (mListener != null) {
                    mListener.onClick(arg1);
                }
                dialog.dismiss();
            }
        };


        setLeftBtnListener(listener);
        setBtnListener(listener);
        setContentView(dlgView);
        setCanceledOnTouch(false);


    }


    public void setCanceledOnTouch(boolean isCanceledOnTouch) {

        setCanceledOnTouchOutside(isCanceledOnTouch);
    }


    public interface OnDiaogClickListener {
        void onClick(int which);
    }
}
